package com.ibeetl.blog.service.impl;

import com.ibeetl.blog.dao.BlogDao;
import com.ibeetl.blog.model.Blog;
import com.ibeetl.blog.service.BlogService;
import org.beetl.ext.fn.StringUtil;
import org.beetl.sql.core.engine.PageQuery;
import org.beetl.sql.core.query.LambdaQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author yibo
 * @date 2019 10 29 17:50
 */

@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogDao blogDao;

    @Override
    public PageQuery<Blog> pageBlog(long pageNumber, long pageSize, String keyword) {
        LambdaQuery<Blog> query = blogDao.createLambdaQuery()
                .andEq(Blog::getDeleteFlag,false);
        if(!StringUtils.isEmpty(keyword)){
             query.andLike(Blog::getTitle, "%"+keyword+"%");
        }
        if (pageSize > 0 && pageNumber > 0){
            return query.page(pageNumber, pageSize);
        }
        return null ;
    }
}
